package cn.piesat.springsecurity.base;

import com.alibaba.fastjson.JSONObject;

public enum CommonCodeEnum implements BaseCodeEnum {
    SUCCESS("0", "success"),
    UNKNOW_ERROR("1", "未知错误"),
    SERVER_BUSY("2", "服务器忙"),
    ACCESS_TOKEN_INVALID("1010001", "无效的access token"),
    REFRESH_TOKEN_INVALID("1010002", "无效的refresh token"),
    ACCEESS_TOKEN_INVALID("1010001", "无效token"),
    INVALID_PARAM("1000", "参数不合法"),
    PARAM_MISS("1001", "参数缺失"),
    TIMESTAMP_ERROR("1002", "时间戳有误"),
    SIGN_ERROR("1003", "数据验签失败"),
    TOKEN_ERROR("1004", "token校验失败"),
    INVALID_SECRET_KEY("1005", "无效的密钥"),
    ENCRYPTION_ERROR("1006", "数据加密失败"),
    DECRYPTION_ERROR("1007", "数据解密失败"),
    AUTHENTICATION_ERROR("1008", "用户认证失败"),
    RPC_CONNECT_FAILED("2000", "远程服务连接失败"),
    RPC_REQUEST_TIMEOUT("2001", "远程服务请求超时"),
    RPC_CALL_EXCEPTION("2002", "远程调用业务系统异常"),
    REDIS_CONNECT_FAILED("3000", "缓存服务连接失败"),
    REDIS_KEY_NOT_FOUND("3001", "没找到指定的key"),
    REDIS_WRITE_DATA_FAILED("3002", "写入数据失败"),
    REDIS_PROCESS_EXCEPTION("3003", "redis数据操作失败"),
    DB_CONNECT_FAILED("3500", "数据库连接失败"),
    DB_PROCESS_EXCEPTION("3501", "数据库操作异常");

    private final String code;
    private final String message;

    private CommonCodeEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    public static CommonCodeEnum getEnumByCode(String code) {
        CommonCodeEnum[] var1 = values();
        int var2 = var1.length;

        for (int var3 = 0; var3 < var2; ++var3) {
            CommonCodeEnum resultEnum = var1[var3];
            if (resultEnum.code.equalsIgnoreCase(code)) {
                return resultEnum;
            }
        }

        return null;
    }

    @Override
    public String toJSONString() {
        JSONObject object = new JSONObject();
        object.put("code", this.code);
        object.put("message", this.message);
        return object.toString();
    }
}
